<?php
/**
 * Users controller class
 *
 */

class TagsController extends Admin_Controller
{

	public function init()
    {
    	parent::init();
    	$this->_table = new Admin_Table_Tags();
    	$this->setActiveCat(425);
    }

    /**
     * index action method
     *
     */
    public function indexAction()
    {
    	$this->page_type = 'list';

    	$lclm = new Llib_List($this->_request, $this->_sess);
    	$lclm->AddParams(array('checkboxes' => true));
    	$lclm->AddColumn('Имя', 'name', array('width' => '10%', 'sort' => 1));
    	$lclm->AddColumn('Еденици измерения', 'unit', array('width' => '80%', 'sort' => 1));

    	$lclm->AddFunc();

    	$lclm->AddData($this->_table->GetDataList($lclm->page, $lclm->s, $lclm->pager_count));

        $this->startContent();
	        $this->view->xmlWriter->startElement("Main");
	        $this->view->assign('List', $lclm->GetList());
		    $this->view->xmlWriter->endElement();
	    $this->view->xmlWriter->endElement();
    }


    public function editAction()
    {
    	$id = $this->_request->getParam('id');
    	if(!($id > 0)) $this->_redirect('/error/e404');

    	$form = new Llib_Form($this->_request);

        if ($this->_request->isPost())
        {
			$d = $form->GetPostedData();
        	if($this->_table->update($d, $id, $this->_user->id)) $form->SetSuccess();
        	else $form->SetError($this->_table->GetError());
        }

        $data = $this->_table->GetDataRow($id);
        $form->AddData($data);

    	$this->startContent();
	        $this->view->xmlWriter->startElement("Main");
	        $this->view->assign('Title', 'Редактировать');
	        $this->view->assign($form->GetFrom());
		    $this->view->xmlWriter->endElement();
	    $this->view->xmlWriter->endElement();
    }

}
